var open_api_request = []
//数据库表容器
var DBtable_config_request = []
//数据库表容器(穿梭框)
var database_tables_transfer = []
//存储规则容器
var storage_rules_config_request = []
//数据文件路径容器(穿梭框)
var files_path_transfer = []
//表格容器
var tablelist = []
//表格容器
var api_tablelist = []
//数据库穿梭框结果容器
var transfer_database_group = []
//文件穿梭框结果容器
var transfer_files_group = []

//初始化请求
$.ajax({
    url: 'http://' + ipm + ':8081/dict/query',
    type: 'POST',
    contentType: 'application/json',
    dataType: 'json',
    data: {},
    success: function (response) {
        console.log(response);
        storageRulesConfigRead(response)
        openApiConfigRead(response)
        // console.log(open_api_request);
        console.log(api_tablelist);
        createTab()
        createFilesTransfer()
    }
});

//初始化请求
$.ajax({
    url: 'http://' + ipm + ':8081/protoTable/queryAllMainnetanceTables',
    type: 'POST',
    contentType: 'application/json',
    dataType: 'json',
    data: {},
    success: function (response) {
        console.log(response);
        DBtable_config_request = response.data
        console.log(DBtable_config_request)
        createDatabaseTransfer()
    }
});

//请求初始化END


//新增规则模态框构建
function createApiModel() {
    $('#apiModal').modal('show');

}
layui.config({
    base: 'step-lay/'
}).use(['form', 'step'], function () {
    var $ = layui.$
        , form = layui.form
        , step = layui.step;
    step.render({
        elem: '#stepForm',
        filter: 'stepForm',
        width: '100%', //设置容器宽度
        stepWidth: '750px',
        height: '600px',
        stepItems: [{
            title: '基础配置'
        }, {
            title: '数据库配置'
        }, {
            title: '数据文件配置'
        }, {
            title: '完成'
        }]
    });
    form.on('submit(formStep)', function (data) {
        // document.getElementById("expired_value").disabled = false
        step.next('#stepForm');
        // if( document.getElementById("expired_select").value == "FV"){
        //     document.getElementById("expired_value").disabled = true
        // }
        return false;
    });
    form.on('submit(formStep2)', function (data) {
        step.next('#stepForm');
        return false;
    });
    form.on('submit(formStep3)', function (data) {
        step.next('#stepForm');
        return false;
    });
    $('.pre').click(function () {
        step.pre('#stepForm');
    });
    $('.next').click(function () {
        step.next('#stepForm');
    });

    //监听指定开关
    form.on('switch(database_close)', function (data) {
        if (this.checked == true) {
            $('#database_transfer_div').show();
        } else {
            $('#database_transfer_div').hide();
        }
        form.render()
    });

    //监听指定开关
    form.on('switch(files_path_close)', function (data) {
        if (this.checked == true) {
            $('#files_path_transfer_div').show();
        } else {
            $('#files_path_transfer_div').hide();
        }
        form.render()
    });

    //监听指定开关
    form.on('switch(database_close_modify)', function (data) {
        if (this.checked == true) {
            $('#database_transfer_div_modify').show();
        } else {
            $('#database_transfer_div_modify').hide();
        }
        form.render()
    });

    //监听指定开关
    form.on('switch(files_path_close_modify)', function (data) {
        if (this.checked == true) {
            $('#files_path_transfer_div_modify').show();
        } else {
            $('#files_path_transfer_div_modify').hide();
        }
        form.render()
    });


    //期限选择框输入限制
    document.getElementById("expired_value").addEventListener('input', function (e) {
        if (document.getElementById("expired_select").value == "min") {
            if (e.target.valueAsNumber > 59) {
                e.target.value = 59; // 当输入值超过最大值时，设置为最大值
            }
        } else if (document.getElementById("expired_select").value == "hour") {
            if (e.target.valueAsNumber > 23) {
                e.target.value = 23; // 当输入值超过最大值时，设置为最大值
            }
        } else if (document.getElementById("expired_select").value == "day") {
            if (e.target.valueAsNumber > 30) {
                e.target.value = 30; // 当输入值超过最大值时，设置为最大值
            }
        } else if (document.getElementById("expired_select").value == "month") {
            if (e.target.valueAsNumber > 11) {
                e.target.value = 11; // 当输入值超过最大值时，设置为最大值
            }
        }
    });

    //期限选择框触发事件
    form.on('select(expired_select)', function (data) {
        console.log(data.value);
        if (data.value == "FV") {
            document.getElementById("expired_value").value = 0
            document.getElementById("expired_value").disabled = true
        } else if (data.value == "min") {
            document.getElementById("expired_value").disabled = false
            document.getElementById("expired_value").value = ""
            document.getElementById("expired_value").max = 59
        } else if (data.value == "hour") {
            document.getElementById("expired_value").disabled = false
            document.getElementById("expired_value").value = ""
            document.getElementById("expired_value").max = 23
        } else if (data.value == "day") {
            document.getElementById("expired_value").disabled = false
            document.getElementById("expired_value").value = ""
            document.getElementById("expired_value").max = 30
        } else if (data.value == "month") {
            document.getElementById("expired_value").disabled = false
            document.getElementById("expired_value").value = ""
            document.getElementById("expired_value").max = 11
        } else if (data.value == "year") {
            document.getElementById("expired_value").disabled = false
        }
        form.render();
    });

    //方法提交
    $('#testSubmitBtn').on('click', function (data) {
        form.submit('api', function (data) { // 注：v2.7.0 新增
            // 回调函数返回结果跟上述 submit 事件完全一致
            field = data.field;
            console.log(data.field)

            // do something

            openApiJosnBuild()
        });
        return false;
    });
})


//新增规则模态框构建END


//创建数据库选择框
function createDatabaseTransfer() {
    var database_arr = DBtable_config_request
    var database_transfer = []
    var ID = 1
    for (var i = 0; i < database_arr.length; i++) {
        var obj = {
            "value": ""
            , "title": ""
        }
        var database_title = ID + "|" + database_arr[i];
        obj.value = database_arr[i];
        obj.title = database_title;
        database_transfer.push(obj);
        ID++
    }

    // console.log(database_transfer);
    layui.use(['transfer', 'layer', 'util'], function () {
        var $ = layui.$
            , transfer = layui.transfer
            , layer = layui.layer
            , util = layui.util;
        //基础效果
        transfer.render({
            elem: '#database_transfer'
            , data: database_transfer
            , id: 'database_selected'
            , title: ['待选字段', '已选字段']
            , showSearch: true
            , width: 300 //定义宽度
            , height: 350 //定义高度
        })
        //批量办法定事件
        util.event('lay-demoTransferActive', {
            getDataDatabase: function (othis) {
                transfer_database_group = []
                var getData = transfer.getData('database_selected'); //获取右侧数据
                //layer.alert(JSON.stringify(getData));
                for (var i = 0; i < getData.length; i++) {
                    transfer_database_group.push(getData[i].value);
                }
                console.log(transfer_database_group);
            }
        });
    });
}
//创建数据库选择框END


//创建数据文件访问选择框
function createFilesTransfer() {
    var rules_arr = storage_rules_config_request.rules_cfg
    var files_transfer = []
    var ID = 1
    // console.log(storage_rules_config_request)

    for (var i = 0; i < rules_arr.length; i++) {
        var obj = {
            "value": ""
            , "title": ""
        }
        var files_title = ID + "|" + rules_arr[i].name + "|" + rules_arr[i].dump_path;
        obj.value = rules_arr[i].id;
        obj.title = files_title;
        files_transfer.push(obj);
        ID++
    }

    layui.use(['transfer', 'layer', 'util'], function () {
        var $ = layui.$
            , transfer = layui.transfer
            , layer = layui.layer
            , util = layui.util;
        //基础效果
        transfer.render({
            elem: '#files_path_transfer'
            , data: files_transfer
            , id: 'files_path_selected'
            , title: ['待选字段', '已选字段']
            , showSearch: true
            , width: 300 //定义宽度
            , height: 350 //定义高度
        })
        //批量办法定事件
        util.event('lay-demoTransferActive', {
            getDataFiles: function (othis) {
                transfer_files_group = []
                var getData = transfer.getData('files_path_selected'); //获取右侧数据
                //layer.alert(JSON.stringify(getData));
                for (var i = 0; i < getData.length; i++) {
                    transfer_files_group.push(getData[i].value);
                }
                console.log(transfer_files_group);
            }
        });
    });
}
//创建数据文件访问选择框END


//生成随机KEY
function createRandomKey() {
    console.log(generateRandomHex(32));
    // $("#key").value = generateRandomHex(32)
    document.getElementById("key").disabled = false
    document.getElementById("key").value = generateRandomHex(32)
    document.getElementById("key").disabled = true

}

function generateRandomHex(digits) {
    let result = '';

    for (let i = 0; i < digits; i++) {
        const randomDecimal = Math.random() * 16;
        const randomHex = Math.floor(randomDecimal).toString(16);
        result += randomHex;
    }

    return result;
}

// console.log(generateRandomHex(8));

//生成随机KEY  END

//提交函数JSON拼接
function openApiJosnBuild() {
    var arrOpenApi = open_api_request.api_cfg;
    var id = open_api_request.max_id;
    id++;
    // var id = ""
    console.log(id)
    var openApiWeb = {
        "cfgType": "11",
        "cfgName": "open_api.json",
        "content": ""
    }

    var openApiSave = {
        "cfg_type": 11,
        "max_id": "",
        "api_cfg": ""
    }

    if (id) {
        api_cfg = {
            "id": "",
            "access_type": [ //访问类型
                { //数据库访问
                    "database_tables": [
                        "ronghe",
                        "hangji"
                    ],
                    "enabled": false //避免修改配置时不需要本内容的情况下，清空后重复配置
                },
                { //数据文件访问, 从存储规则中选择（单选或多选），获取"dump_path": ["空间1", "航迹", "/data/123"]，赋值到files_path
                    "files_path_id": [],
                    "files_path": [ //空间 + 类型 + 路径："空间1","检测视频","jscp_c"
                        [],
                        []
                    ],
                    "enabled": true
                }
            ],
            "expired": { "val": 2, "unit": "day" },
            "key": "",
            "deadline": "yyyy/mm/dd HH:mm",
            "enabled": true,
            "comment": ""
        }
        api_cfg.id = id;
    } else {
        arrOpenApi = []
        api_cfg = {
            "id": "",
            "access_type": [ //访问类型
                { //数据库访问
                    "database_tables": [
                        "ronghe",
                        "hangji"
                    ],
                    "enabled": false //避免修改配置时不需要本内容的情况下，清空后重复配置
                },
                { //数据文件访问, 从存储规则中选择（单选或多选），获取"dump_path": ["空间1", "航迹", "/data/123"]，赋值到files_path
                    "files_path_id": [],
                    "files_path": [ //空间 + 类型 + 路径："空间1","检测视频","jscp_c"
                        [],
                        []
                    ],
                    "enabled": true
                }
            ],
            "expired": { "val": 2, "unit": "day" },
            "key": "",
            "deadline": "yyyy/mm/dd HH:mm",
            "enabled": true,
            "comment": ""
        }
        id = 0;
        api_cfg.id = 0;
    }
    console.log(field)
    api_cfg.access_type[0].database_tables = transfer_database_group
    if (field.database_close == "on") {
        api_cfg.access_type[0].enabled = true
    } else {
        api_cfg.access_type[0].enabled = false
    }
    var files_path_arr = []
    console.log(transfer_files_group)

    for (var i = 0; i < transfer_files_group.length; i++) {
        for (var j = 0; j < storage_rules_config_request.rules_cfg.length; j++) {
            if (transfer_files_group[i] == storage_rules_config_request.rules_cfg[j].id) {
                files_path_arr.push(storage_rules_config_request.rules_cfg[j].dump_path)
                console.log(storage_rules_config_request.rules_cfg[j].dump_path)

            }
        }
    }
    api_cfg.access_type[1].files_path_id = transfer_files_group
    api_cfg.access_type[1].files_path = files_path_arr
    if (field.files_path_close == "on") {
        api_cfg.access_type[1].enabled = true
    } else {
        api_cfg.access_type[1].enabled = false
    }
    api_cfg.comment = field.comment
    api_cfg.expired.val = parseInt(field.expired_value)
    api_cfg.expired.unit = field.expired_select
    api_cfg.key = field.key
    // api_cfg.deadline 
    var time = new Date()
    console.log(time)
    var year = time.getFullYear()
    var months = time.getMonth()
    var date = time.getDate()
    var hour = time.getHours()
    var min = time.getMinutes()
    console.log(hour)
    console.log(min)
    console.log(year)
    console.log(months)
    console.log(date)
    var expired_val = parseInt(field.expired_value)
    console.log(expired_val)
    var expired_unit = field.expired_select
    console.log(expired_unit)
    if (expired_unit == "min") {
        if ((expired_val + min) < 60) {
            api_cfg.deadline = year + "/" + (months + 1) + "/" + date + " " + hour + ":" + (min + expired_val)
        } else {
            api_cfg.deadline = year + "/" + (months + 1) + "/" + date + " " + (hour + 1) + ":" + (min + expired_val - 60)
        }
    } else if (expired_unit == "hour") {
        if ((expired_val + hour) < 24) {
            api_cfg.deadline = year + "/" + (months + 1) + "/" + date + " " + (hour + expired_val) + ":" + min
        } else {
            api_cfg.deadline = year + "/" + (months + 1) + "/" + (date + 1) + " " + (hour + expired_val - 24) + ":" + min
        }
    } else if (expired_unit == "day") {
        time.setDate(time.getDate() + expired_val)
        date = time.getDate()
        months = time.getMonth()
        year = time.getFullYear()
        api_cfg.deadline = year + "/" + (months + 1) + "/" + date + " " + hour + ":" + min
    } else if (expired_unit == "month") {
        time.setMonth(time.getMonth() + expired_val)
        date = time.getDate()
        months = time.getMonth()
        year = time.getFullYear()
        api_cfg.deadline = year + "/" + (months + 1) + "/" + date + " " + hour + ":" + min
    } else if (expired_unit == "year") {
        time.setFullYear(time.getFullYear() + expired_val)
        date = time.getDate()
        months = time.getMonth()
        year = time.getFullYear()
        api_cfg.deadline = year + "/" + (months + 1) + "/" + date + " " + hour + ":" + min
    } else if (expired_unit == "FV") {
        api_cfg.deadline = 0
    }
    console.log(api_cfg.deadline)
    arrOpenApi.push(api_cfg)
    openApiSave.api_cfg = arrOpenApi
    openApiSave.max_id = id
    console.log(openApiSave)
    openApiWeb.content = JSON.stringify(openApiSave)
    console.log(openApiWeb)
    postQuestSave(openApiWeb);
    alert("新增成功！");
    window.location.reload();
}

function createTab() {
    $("#table_page").bootstrapTable('destroy').bootstrapTable({
        data: api_tablelist,
        dataType: 'json',
        striped: true,                      //是否显示行间隔色
        cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
        pagination: true,                   //是否显示分页（*）
        sortable: true,                     //是否启用排序
        sortOrder: "asc",                   //排序方式
        sidePagination: "client",           //分页方式：client客户端分页，server服务端分页（*）
        pageNumber: 1,                      //初始化加载第一页，默认第一页,并记录
        pageSize: 10,                     //每页的记录行数（*）
        pageList: [10, 25, 50, 100],        //可供选择的每页的行数（*）
        search: false,                      //是否显示表格搜索
        strictSearch: true,
        minimumCountColumns: 1,             //最少允许的列数
        clickToSelect: true,                //是否启用点击选中行
        uniqueId: "id",                     //每一行的唯一标识，一般为主键列
        cardView: false,                    //是否显示详细视图
        detailView: false,                  //是否显示父子表
        onEditableSave: onRuleEditableSave,
        columns: [
            {
                field: 'ID',
                align: 'center',
                title: '序号',
                width: 60,
                formatter: function (value, row, index) {
                    return index + 1;
                }
            }, {
                field: 'comment',
                title: '描述'
            }, {
                field: 'database_tables',
                title: '数据库访问',
                width: 120,
                align: 'center',
                valign: 'middle',
                formatter: function (value, row, index) {
                    var result = "";
                    result += "<a href='javascript:;' class='btn btn-xs blue' onclick=\"database_tables_modify('" + index + "','" + value + "')\" title='编辑'><span class='feather-edit'></span></a>";
                    return result;
                }
            }, {
                field: 'files_path_id',
                align: 'center',
                title: '数据文件访问',
                width: 60,
                formatter: function (value, row, index) {
                    var result = "";
                    result += "<a href='javascript:;' class='btn btn-xs blue' onclick=\"files_path_modify('" + index + "','" + value + "')\" title='编辑'><span class='feather-edit'></span></a>";
                    return result;
                }
            }, {
                field: 'key',
                title: 'KEY'
            }, {
                field: 'deadline',
                title: '过期时间'
            }, {
                field: 'enabled',
                title: '使能',
                editable: {
                    type: 'select',
                    title: '值类型',
                    source: [{
                        value: "true",
                        text: "启用"
                    }, {
                        value: "false",
                        text: "禁用"
                    }]
                }
            }, {
                field: 'id',
                align: 'center',
                title: '删除',
                width: 80,
                formatter: function (value, row, index) {
                    var id = value;
                    var result = "";
                    result += "<a href='javascript:;' class='btn btn-xs red' onclick=\"open_api_delete(" + id + ")\" title='删除'><span class='feather-trash-2'></span></a>";
                    return result;
                }
            }
        ],
    });


}

//编辑保存
function onRuleEditableSave(field, row, rowIndex, oldValue, $el) {
    var data = $("#table_page").bootstrapTable('getData');
    var objChange = data[rowIndex];
    var idChange = objChange.id;

    var arr = open_api_request.api_cfg;
    var openApiWeb = {
        "cfgType": "11",
        "cfgName": "open_api.json",
        "content": ""
    }

    var openApiSave = {
        "cfg_type": 11,
        "max_id": "",
        "api_cfg": ""
    }
    if (field == "enabled") {
        for (var i = 0; i < arr.length; i++) {
            if (arr[i].id == idChange) {
                if (row[field] == "true") {
                    arr[i].enabled = true
                } else {
                    arr[i].enabled = false
                }
            }
        }
    }
    openApiSave.api_cfg = arr;
    openApiSave.max_id = open_api_request.max_id;
    openApiWeb.content = JSON.stringify(openApiSave)
    console.log(openApiSave)
    refresh_table(openApiWeb)
    layer.msg('修改成功', { icon: 1 });
}



//数据库表修改
function database_tables_modify(rowIndex, value) {
    console.log(rowIndex)
    console.log(value)
    var database_enabled = open_api_request.api_cfg[rowIndex].access_type[0].enabled
    console.log(database_enabled)
    layui.use(['form'], function () {
        var form = layui.form;
        if (database_enabled == true) {
            document.getElementById("database_close_modify").checked = true
            $('#database_transfer_div_modify').show();
        } else {
            document.getElementById("database_close_modify").checked = false
            $('#database_transfer_div_modify').hide();
        }
        form.render()
    });
    database_modify_id = open_api_request.api_cfg[rowIndex].id
    console.log(database_modify_id)
    var modify_arr = value.split(",")
    var database_arr = DBtable_config_request
    var database_transfer = []
    var ID = 1
    for (var i = 0; i < database_arr.length; i++) {
        var obj = {
            "value": ""
            , "title": ""
        }
        var database_title = ID + "|" + database_arr[i];
        obj.value = database_arr[i];
        obj.title = database_title;
        database_transfer.push(obj);
        ID++
    }

    layui.use(['transfer', 'layer', 'util'], function () {
        var $ = layui.$
            , transfer = layui.transfer
            , layer = layui.layer
            , util = layui.util;
        //基础效果
        transfer.render({
            elem: '#database_transfer2'
            , data: database_transfer
            , id: 'database_selected'
            , title: ['待选字段', '已选字段']
            , value: modify_arr
            , showSearch: true
            , width: 300 //定义宽度
            , height: 350 //定义高度
        })
        //批量办法定事件
        util.event('lay-demoTransferActive', {
            database_tables_modify: function (othis) {
                transfer_database_group = []
                var getData = transfer.getData('database_selected'); //获取右侧数据
                //layer.alert(JSON.stringify(getData));
                for (var i = 0; i < getData.length; i++) {
                    transfer_database_group.push(getData[i].value);
                }
                console.log(transfer_database_group);
                var arrOpenApi = open_api_request.api_cfg;
                // var arrSRule = storage_rules_config_request.rules_cfg;
                console.log(arrOpenApi);
                for (var i = 0; i < arrOpenApi.length; i++) {
                    if (arrOpenApi[i].id == database_modify_id) {
                        arrOpenApi[i].access_type[0].database_tables = transfer_database_group
                        arrOpenApi[i].access_type[0].enabled = document.getElementById("database_close_modify").checked
                    }
                }
                var openApiWeb = {
                    "cfgType": "11",
                    "cfgName": "open_api.json",
                    "content": ""
                }
                open_api_request.api_cfg = arrOpenApi;
                openApiWeb.content = JSON.stringify(open_api_request)
                console.log(openApiWeb)
                console.log(arrOpenApi)
                postQuestSave(openApiWeb);
                // window.location.reload();    
                alert("修改成功")
            }
        });
    });
    $('#databaseModal').modal('show');
}



//文件类型修改
function files_path_modify(rowIndex, value) {
    console.log(rowIndex)
    console.log(value)
    //是否启用
    var files_enabled = open_api_request.api_cfg[rowIndex].access_type[1].enabled
    console.log(files_enabled)
    layui.use(['form'], function () {
        var form = layui.form;
        if (files_enabled == true) {
            document.getElementById("files_path_close_modify").checked = true
            $('#files_path_transfer_div_modify').show();
        } else {
            document.getElementById("files_path_close_modify").checked = false
            $('#files_path_transfer_div_modify').hide();
        }
        form.render()
    });
    files_modify_id = open_api_request.api_cfg[rowIndex].id
    console.log(files_modify_id)
    var rules_arr = storage_rules_config_request.rules_cfg
    var files_transfer = []
    var ID = 1
    // console.log(storage_rules_config_request)

    for (var i = 0; i < rules_arr.length; i++) {
        var obj = {
            "value": ""
            , "title": ""
        }
        var files_title = ID + "|" + rules_arr[i].name + "|" + rules_arr[i].dump_path;
        obj.value = rules_arr[i].id;
        obj.title = files_title;
        files_transfer.push(obj);
        ID++
    }
    layui.use(['transfer', 'layer', 'util'], function () {
        var $ = layui.$
            , transfer = layui.transfer
            , layer = layui.layer
            , util = layui.util;
        //基础效果
        transfer.render({
            elem: '#files_path_transfer2'
            , data: files_transfer
            , id: 'files_path_selected'
            , title: ['待选字段', '已选字段']
            , value: value
            , showSearch: true
            , width: 300 //定义宽度
            , height: 350 //定义高度
        })
        //批量办法定事件
        util.event('lay-demoTransferActive', {
            files_path_modify: function (othis) {
                transfer_files_group = []
                var getData = transfer.getData('files_path_selected'); //获取右侧数据
                //layer.alert(JSON.stringify(getData));
                for (var i = 0; i < getData.length; i++) {
                    transfer_files_group.push(getData[i].value);
                }
                console.log(transfer_files_group);
                var arrOpenApi = open_api_request.api_cfg;
                console.log(arrOpenApi);
                var files_path_arr = []

                for (var i = 0; i < transfer_files_group.length; i++) {
                    for (var j = 0; j < storage_rules_config_request.rules_cfg.length; j++) {
                        if (transfer_files_group[i] == storage_rules_config_request.rules_cfg[j].id) {
                            files_path_arr.push(storage_rules_config_request.rules_cfg[j].dump_path)
                            console.log(storage_rules_config_request.rules_cfg[j].dump_path)
                        }
                    }
                }
                for (var i = 0; i < arrOpenApi.length; i++) {
                    if (arrOpenApi[i].id == files_modify_id) {
                        arrOpenApi[i].access_type[1].files_path = files_path_arr
                        arrOpenApi[i].access_type[1].files_path_id = transfer_files_group
                        arrOpenApi[i].access_type[1].enabled = document.getElementById("files_path_close_modify").checked
                    }
                }
                var openApiWeb = {
                    "cfgType": "11",
                    "cfgName": "open_api.json",
                    "content": ""
                }
                open_api_request.api_cfg = arrOpenApi;
                openApiWeb.content = JSON.stringify(open_api_request)
                console.log(openApiWeb)
                console.log(arrOpenApi)
                postQuestSave(openApiWeb);
                alert("修改成功")
            }
        });
    });
    $('#filesModal').modal('show');
}

//开放接口，删除函数
function open_api_delete(args) {
    var arrOpenApi = open_api_request.api_cfg;
    // var arrSRule = storage_rules_config_request.rules_cfg;
    console.log(arrOpenApi);
    console.log(args);
    for (var i = 0; i < arrOpenApi.length; i++) {
        if (arrOpenApi[i].id == args) {
            arrOpenApi.splice(i, 1);
        }
    }
    var openApiWeb = {
        "cfgType": "11",
        "cfgName": "open_api.json",
        "content": ""
    }
    open_api_request.api_cfg = arrOpenApi;
    openApiWeb.content = JSON.stringify(open_api_request)
    console.log(openApiWeb)
    console.log(arrOpenApi)
    refresh_table(openApiWeb)
    layer.msg('删除成功', { icon: 1 });
}


//动态刷新表
function refresh_table(openApiWeb) {
    var xhr = new XMLHttpRequest();
    // 配置请求
    xhr.open('POST', 'http://' + ipm + ':8081/dict/save', true);
    xhr.setRequestHeader('content-Type', 'application/json');
    // 发送 JSON 数据
    xhr.send(JSON.stringify(openApiWeb));
    // 监听请求的状态
    xhr.onreadystatechange = function () {
        console.log(xhr.readyState);
        if (xhr.readyState === 4 && xhr.status === 200) {
            console.log(xhr.responseText);
            $.ajax({
                url: 'http://' + ipm + ':8081/dict/query',
                type: 'POST',
                contentType: 'application/json',
                dataType: 'json',
                data: {},
                success: function (response) {
                    api_tablelist = []
                    openApiConfigRead(response)
                    createTab()
                }
            });
        }
    };
}